﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DARE.Save.DataStructures
{
    public class CSceneData: ISaveData
    {
        public string Name;
        public Dictionary<string, CRender3DData> m_render3ds = new Dictionary<string, CRender3DData>();
        public Dictionary<string, CHUDData> m_HUDsystems = new Dictionary<string, CHUDData>();

        public string m_activeRender3d = null;
        public string m_activeHudSystem = null;

        public void FillDataStructure(object scene)
        {
            CScene scn = scene as CScene;
            Name = scn.Name;
            foreach (CHUDSystem hud in scn.HUDSystem.Values)
            {
                CHUDData HUDData = new CHUDData();
                HUDData.FillDataStructure(hud);
                m_HUDsystems.Add(hud.Name, HUDData);
            }
            foreach (CRender3D render in scn.Render3D.Values)
            {
                CRender3DData renderData = new CRender3DData();
                renderData.FillDataStructure(render);
                m_render3ds.Add(render.Name, renderData);
            }
            if (scn.ActiveHudSystem != null)
                m_activeHudSystem = scn.ActiveHudSystem.Name;
            if (scn.ActiveRender3D != null)
                m_activeRender3d = scn.ActiveRender3D.Name;
        }

        public void FillFromDataStructure(out object scene, params object[] paramsData)
        {
            scene = new CScene(Name);
            foreach (CHUDData hudData in m_HUDsystems.Values)
            {
                object hud;
                hudData.FillFromDataStructure(out hud);
                (scene as CScene).RegisterRenderer(hud as CHUDSystem);
            }
            foreach (CRender3DData renderData in m_render3ds.Values)
            {
                object render;
                renderData.FillFromDataStructure(out render, scene);
                (scene as CScene).RegisterRenderer(render as CRender3D);
            }
            if (m_activeRender3d != null)
                (scene as CScene).SetActiveRender(m_activeRender3d);
            if (m_activeHudSystem != null) 
                (scene as CScene).SetActiveRender(m_activeHudSystem);
        }
    }
}
